// @ts-ignore
import Mock from 'mockjs'


// Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
// Mock.XHR.prototype.send = function() {
//     if (this.custom.xhr) {
//         this.custom.xhr.withCredentials = this.withCredentials || false
//         this.custom.xhr.responseType = this.responseType
//     }
//     this.proxy_send(...arguments)
// }
//    "url": "/list/table",
// Mock.setup({
//   timeout: '350-600'
// })

const cunt = 50
const tableData =[]
for (let i = 0; i< cunt ; i++ ){
    tableData.push(Mock.mock({
        id: '@increment',
        name: '@cname()',
        'age|18-40': 1,
        'sex|1': [1, 0],
        'status|1': [1, 0],
        email: '@email',
        msg: '@cparagraph'
    }))
}
// 数据集合
Mock.mock('/list/table', 'post', (params) => {
    const body = JSON.parse(params.body)
    const [ num, size, name, status ] = [ body.pageNumber, body.pageSize, body.name, body.status ]
    let searchList = []
    const data = []
    tableData.forEach(item =>{
      // 状态搜索
      if (item.status === status) {
         data.push(item)
         searchList = data
      }
      if (item.name === name ) searchList = [item]
      if (name === '' && status == null) searchList = tableData
    })
    data.forEach(item =>{
      if (item.name === name) searchList = [item]
    })
    const newList = searchList.filter((item, index) => index < size * num && index >= size * (num - 1))
    return {
      message: 'ok',
      success: true,
      data: {
        total: searchList.length,
        page: newList
      },
   }
});

export default Mock
